<?php
defined('BASEPATH') or exit('No direct script access allowed');
require APPPATH.'libraries/BaseApiController.php';
class user extends  BaseApiController
{
   public function index(){
   }
   
   public function login(){
	
	   $data=$this->getFields([
		   array("name","required","手机号码",""),
		   array("password","required","登录密码","")
	   ]);
	   $row=$this->db->where("name",$data["name"])->get("users")->row_array();
	

		if($row){
			if($row["password"]==$data["password"]){
				
				//查询机构信息
				$school=$this->db->where("schcode",$row["schcode"])->get("school")->row_array();
				$this->WRITE("code",1);		
				$tokendata=array(
					"schcode"=>$row["schcode"],
					"schtitle"=>$school["title"],
					"expired"=>$school["expdate"]
				);
				
				$userinfo=array(
				 "uid"=>$row["uid"],
				 "name"=>$row["name"],
				 "nickname"=>$row["nickname"]
				);
				$school=array(
				 "schcode"=>$school["schcode"],
				 "schtitle"=>$school["title"],
				 "expdate"=>$school["expdate"]
				);
				$this->WRITE("school",$school);
				$this->WRITE("userinfo",$userinfo);
				$token=$this->createToken($tokendata);
				$this->WRITE("token",$token);
				$this->WRITE("msg","登录成功!");
				$this->RESPONSE();
			}else{
				$this->WRITE("code",0);
				$this->WRITE("msg","账号或密码错误!");
				$this->RESPONSE();
			}
		}else{
			$this->WRITE("code",0);
			$this->WRITE("msg","账号密码错误!");
			$this->RESPONSE();
		}

   }
   
}